<?php

namespace JLPay\Models\Marketing;

use JLPay\Models\BaseResponse;

/**
 * 商户活动余额数据
 */
class MerchantActivityBalanceData
{
    /**
     * 活动ID
     * @var string|null
     */
    public ?string $actId = null;

    /**
     * 商户号
     * @var string|null
     */
    public ?string $merchNo = null;

    /**
     * 终端号
     * @var string|null
     */
    public ?string $termNo = null;

    /**
     * 计费类型
     * @var string|null
     */
    public ?string $sortValue = null;

    /**
     * 总额度
     * @var string|null
     */
    public ?string $totalQuota = null;

    /**
     * 已使用额度
     * @var string|null
     */
    public ?string $usedQuota = null;

    /**
     * 剩余额度
     * @var string|null
     */
    public ?string $remainingQuota = null;

    /**
     * 开始时间
     * @var string|null
     */
    public ?string $startTime = null;

    /**
     * 结束时间
     * @var string|null
     */
    public ?string $endTime = null;

    /**
     * 状态
     * @var string|null
     */
    public ?string $status = null;

    /**
     * 设置活动ID
     *
     * @param string $actId 活动ID
     * @return $this
     */
    public function setActId(string $actId): self
    {
        $this->actId = $actId;
        return $this;
    }

    /**
     * 设置商户号
     *
     * @param string $merchNo 商户号
     * @return $this
     */
    public function setMerchNo(string $merchNo): self
    {
        $this->merchNo = $merchNo;
        return $this;
    }

    /**
     * 设置终端号
     *
     * @param string $termNo 终端号
     * @return $this
     */
    public function setTermNo(string $termNo): self
    {
        $this->termNo = $termNo;
        return $this;
    }

    /**
     * 设置计费类型
     *
     * @param string $sortValue 计费类型
     * @return $this
     */
    public function setSortValue(string $sortValue): self
    {
        $this->sortValue = $sortValue;
        return $this;
    }

    /**
     * 设置总额度
     *
     * @param string $totalQuota 总额度
     * @return $this
     */
    public function setTotalQuota(string $totalQuota): self
    {
        $this->totalQuota = $totalQuota;
        return $this;
    }

    /**
     * 设置已使用额度
     *
     * @param string $usedQuota 已使用额度
     * @return $this
     */
    public function setUsedQuota(string $usedQuota): self
    {
        $this->usedQuota = $usedQuota;
        return $this;
    }

    /**
     * 设置剩余额度
     *
     * @param string $remainingQuota 剩余额度
     * @return $this
     */
    public function setRemainingQuota(string $remainingQuota): self
    {
        $this->remainingQuota = $remainingQuota;
        return $this;
    }

    /**
     * 设置开始时间
     *
     * @param string $startTime 开始时间
     * @return $this
     */
    public function setStartTime(string $startTime): self
    {
        $this->startTime = $startTime;
        return $this;
    }

    /**
     * 设置结束时间
     *
     * @param string $endTime 结束时间
     * @return $this
     */
    public function setEndTime(string $endTime): self
    {
        $this->endTime = $endTime;
        return $this;
    }

    /**
     * 设置状态
     *
     * @param string $status 状态
     * @return $this
     */
    public function setStatus(string $status): self
    {
        $this->status = $status;
        return $this;
    }

    /**
     * 将对象转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        $result = [];
        if ($this->actId !== null) $result['act_id'] = $this->actId;
        if ($this->merchNo !== null) $result['merch_no'] = $this->merchNo;
        if ($this->termNo !== null) $result['term_no'] = $this->termNo;
        if ($this->sortValue !== null) $result['sort_value'] = $this->sortValue;
        if ($this->totalQuota !== null) $result['total_quota'] = $this->totalQuota;
        if ($this->usedQuota !== null) $result['used_quota'] = $this->usedQuota;
        if ($this->remainingQuota !== null) $result['remaining_quota'] = $this->remainingQuota;
        if ($this->startTime !== null) $result['start_time'] = $this->startTime;
        if ($this->endTime !== null) $result['end_time'] = $this->endTime;
        if ($this->status !== null) $result['status'] = $this->status;
        return $result;
    }
}

/**
 * 商户活动余额查询响应模型
 */
class MerchantActivityBalanceQueryResponse extends BaseResponse
{
    /**
     * 商户活动余额数据列表
     * @var MerchantActivityBalanceData[]
     */
    public array $data = [];

    /**
     * 构造函数
     *
     * @param array|null $responseDict 响应字典
     */
    public function __construct(?array $responseDict = null)
    {
        parent::__construct($responseDict);
        
        if ($responseDict && isset($responseDict['data']) && is_array($responseDict['data'])) {
            foreach ($responseDict['data'] as $item) {
                $dataItem = new MerchantActivityBalanceData();
                
                if (isset($item['act_id'])) $dataItem->setActId($item['act_id']);
                if (isset($item['merch_no'])) $dataItem->setMerchNo($item['merch_no']);
                if (isset($item['term_no'])) $dataItem->setTermNo($item['term_no']);
                if (isset($item['sort_value'])) $dataItem->setSortValue($item['sort_value']);
                if (isset($item['total_quota'])) $dataItem->setTotalQuota($item['total_quota']);
                if (isset($item['used_quota'])) $dataItem->setUsedQuota($item['used_quota']);
                if (isset($item['remaining_quota'])) $dataItem->setRemainingQuota($item['remaining_quota']);
                if (isset($item['start_time'])) $dataItem->setStartTime($item['start_time']);
                if (isset($item['end_time'])) $dataItem->setEndTime($item['end_time']);
                if (isset($item['status'])) $dataItem->setStatus($item['status']);
                
                $this->data[] = $dataItem;
            }
        }
    }

    /**
     * 将响应对象转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        $result = parent::toArray();
        if (!empty($this->data)) {
            $result['data'] = array_map(function($item) {
                return $item->toArray();
            }, $this->data);
        }
        return $result;
    }
} 